import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'
import {personalLnformation} from '../api/api'
import store from '../store'
// import Antd from 'ant-design-vue';
// Vue.use(Antd);


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/index"
  },
  {
    path: '/index',
    name: 'Index',
    component: Index
  },
  {
    path: '/detail',
    name: 'Detail',
    component: ()=>import("../views/Detail")
  },
  {
    path: '/mine',
    name: 'Mine',
    meta:{
      needLogin:true
    },
    component: ()=>import("../views/Mine")
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// let vue = new Vue()
import { message } from 'ant-design-vue';
Vue.config.productionTip = false;
router.beforeEach((to, from,next) => {
  if(to.meta.needLogin){
    personalLnformation().then(res=>{
      if(res.code==0){
        next()
      }else {
        next('/')
        message.warning("请登录!!!")
        // vue.$message.warning('请登录!')
        store.commit('changLogin',true)
        // console.log(store)

        // alert("请登录")
        // prompt("请登录")
      }
    })
  }else {
    next()
  }
})

export default router
